* Last edited: 2023, April 6
* This is the Master .do file to replicate the results in 
* "A Denial A Day Keeps the Doctor Away", by Dunn, Gottlieb, Shapiro, Sonnenstuhl, Tebaldi
* 
* This file sets up paths and file names for data used in the article.
* The file then invokes a DO file that runs the scripts needed for the article.

***** SETTING SEED FOR REPLICATION
set seed 5112023


*****************************
******* USER NEEDS TO RUN THIS DO-FILE FROM THE code FOLDER 
*****************************
*****************************	
******* FOLDERS CONTAINING RAW DATA:
global raw_input	 `"../../proprietary_data"'	// Directory for IQVIA, mover, cross-state, provider data, zip-location merge
global public_data   `"../../public_data"'		// Directory for all publicly accessible data 										 
*****************************

*****************************
******* PATHS for OUTPUT:
global output_parent        `"../../output"'
global paperinputs          `"../../manuscript/PaperInputs"' 
global output 				`"$output_parent/replication"'
global temp					`"$output/temp"'														
global indices 				`"$output/indices"'
*****************************

***** SETTINGS
global iterations 100 // MAX # iterations for MLE estimations
global group_threshold 3 // size cutoff for small/large practice definition
	
********************************************
********************************************
** basic setup
set more off
clear all 
set maxvar 5000
set matsize 11000

*****************************************
*****************************************
/* Packages needed */
*****************************************
*****************************************
local PACKAGES gtools asgen parallel maptile spmap ftools ranktest reghdfe ivreg2 ivreghdfe coefplot
foreach package in `PACKAGES' {
	capture which `package'
	if _rc==111 ssc install `package'
}

capture which estout
if _rc==111 net install estout, from("http://fmwww.bc.edu/RePEc/bocode/e")
capture maptile_install using "http://files.michaelstepner.com/geo_state.zip"
*****************************************
*****************************************

***********************************
// auxiliary names of data paths
***********************************
global rc_input				`"$public_data"'			// Directory for reason code classification 			
global control_var 			`"$public_data"'			// Direcotry for control vars for mover and x-state regs
global geography_files 		`"$public_data"'			// Directory for geography mapping files 
global zip_input 	 		`"$public_data"'		    // Directory for zip code income file 

***********************************
//filenames
***********************************
global raw_data_2015 "merged_RC_RCS_line_dx2015.dta"							// 2015 Raw Data
global raw_data_2014 "merged_RC_RCS_line_dx2014.dta"							// 2014 Raw Data
global raw_data_2013 "merged_RC_RCS_line_dx2013.dta"							// 2013 Raw Data
global line_file_temp "IQVIA_processed_unmerged.dta"							// Main Data (merge from the MDPPAS data is missing)
global line_file "IQVIA_processed.dta"											// Main Data
global classification_file "code_classification.dta"							// Code Classification File 
global zip_code_income "zip_code_income.dta"									// Zip-code income file 
global zip_code_merge  "zip_code_npi_merge.dta"									// Zip-code npi merge file 
global mover_file	"mover_only_data_MDPPAS_abe_11_5_21_FIPS.dta"				// Name of the mover data file
global mover_file_size	"mover_only_data_MDPPAS_abe_8_18_22_FIPS_wSize.dta"		// Name of the mover data file
global x_state_file "fullgroupdatacross_state8_22_2022.dta"						// Name of the Cross State Data File 
global x_state_file_regression "fullgroupdatacross_state8_22_2022.dta"			// Name of the Cross State Data File 
global x_state_size_merge "fullgroupdatacross_state_average_group_size.dta"		// Name of the File with the average group size 
global x_state_file_size "fullgroupdatacross_state_SIZE"						// Name of the Cfoss State Data File with the average group size
global x_state_file_size_provider "fullgroupdatacross_state_idw_provider_SIZE"	// Name of the Cfoss State Data File with the average group size and provider info 
global zip_to_county "zip_to_county.dta" 										// Name of the ZIP to County Mapping file 
global provider_file "ref_providers.dta"										// Name of the IDW provider ID and NPI file 
global provider_mapping "npi_idw_map_iqvia_provider_data.dta"					// name of the provider data mapping file 
global full_mover_file  "full_movers_data_1_30_20_supp.dta"						// full mover data file 
********************************************************************************
	
***** LAUNCH *****
do `"00_Run.do"'
******************



 
 
 
